<template>
  <div>
    <el-row type="flex" justify="center" align="middle" class="licc-goods-goods-list-top-row">
      <el-row type="flex" justify="center" align="middle"  style="width:1100px;">
        <el-col class="liccc-goods-goods-list-bread">
          <router-link to="/home">首页</router-link>
          <router-link
            v-for="(category, index) in categories"
            :key="category.id"
            :to="{path:'/goodsList',query:{catId:category.id,catName:category.catName}}" target="_blank">
            <a><b>&gt;</b>{{category.catName}}</a>
          </router-link>
        </el-col>
      </el-row>
    </el-row>

    <el-row type="flex" justify="center" align="middle" class="licc-goods-goods-list-top-row">
      <el-row type="flex" justify="center" align="middle"  style="width:1100px;">
        <el-col class="licc-goods-goods-list-center">
          <el-row>
            <el-col class="licc-goods-goods-list-hr-col"><div class="licc-goods-goods-list-hr-div"></div></el-col>
            <el-col style="width: 160px; line-height: 30px; color:#999;">{{query.catName}}</el-col>
            <el-col class="licc-goods-goods-list-hr-col"><div class="licc-goods-goods-list-hr-div"></div></el-col>
          </el-row>
          <el-row style="width: 100%; height: 300px; line-height: 300px; background-color: #fff" v-show="goodsList.length>0?false:true">
            该分类下暂无商品
          </el-row>
          <el-row v-show="goodsList.length>0?true:false">
            <el-col class="licc-goods-goods-list-col"
                    v-for="(goodsInfo, index) in goodsList" :key="index">
              <div class="licc-goods-goods-list-info">
                <div class="licc-goods-goods-list-img">
                  <!--<a href="">-->
                  <router-link :to="{path:'/goodsInfo',query:{goodsId:goodsInfo.id,catId:goodsInfo.catId}}" target="_blank">
                    <el-image style="width:250px; height:320px" :src="goodsInfo.imgUrl" fit="cover" title="图片解释"></el-image>
                  </router-link>
                  <!--</a>-->
                </div>
                <div class="licc-goods-goods-list-price">
                  <strong class="J_price" data-price-plus="1"><em>¥</em><i>{{goodsInfo.shopPrice}}</i></strong>
                </div>
                <div class="licc-goods-goods-list-name">
                  <router-link :to="{path:'/goodsInfo',query:{goodsId:goodsInfo.id,catId:goodsInfo.catId}}" title="文字解释" target="_blank">
                    <em>{{goodsInfo.goodsName}}-{{goodsInfo.goodsBrief}}</em>
                  </router-link>
                  <!--</a>-->
                </div>
                <div class="licc-goods-commit">
                  <strong>已有<router-link :to="{path:'/goodsInfo',query:{goodsId:goodsInfo.id,catId:goodsInfo.catId}}" target="_blank">{{commentNumShowRule(goodsInfo.commit)}}</router-link>条评价</strong>
                </div>
                <div class="licc-goods-integral">
                  <strong>销量<router-link :to="{path:'/goodsInfo',query:{goodsId:goodsInfo.id,catId:goodsInfo.catId}}" target="_blank">{{commentNumShowRule(goodsInfo.integral)}}</router-link></strong>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-row>

    <el-row type="flex" justify="center" align="middle" class="licc-goods-goods-list-top-row">
      <el-row type="flex" justify="center" align="middle"  style="width:1100px;">
        <el-col class="licc-goods-list-pagination">
          <div style="float: right">
            <div class="block">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-size="pagesize"
                layout="prev, pager, next, jumper"
                :total="goodsTotal">
              </el-pagination>
            </div>
          </div>
        </el-col>
      </el-row>
    </el-row>
  </div>
</template>
<script>
import goodsListApi from "@/api/goodsList"
export default {
  name: 'page404',
  data() {
    return {
      query: this.$route.query,
      categories: [],
      goodsList:[],
      currentPage: 1,
      pagesize:12,
      goodsTotal:0,
    }
  },
  created(){
    this.initPage();
  },
  methods: {
    initPage() {
      this.goodsList = [];
      let params = {
        catId: this.query.catId,
        pagesize: this.pagesize,
        currentPage: this.currentPage
      }
      goodsListApi.initShopgoodsList(params).then(res => {
        this.categories = res.data.categories;
        this.goodsList = res.data.goods;
        this.goodsTotal = res.data.iPage.total;
      }).catch(() => {

      })
    },
    /** 分页--开始 **/
    handleSizeChange(val) {
      this.pagesize = val;
      this.initPage();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.initPage();
      console.log(`当前页: ${val}`);
    },
    /** 分页--结束 **/
    commentNumShowRule(num){
      if (num<10){
        return ''+num;
      } else if (num < 100){
        return (parseInt(num/10)*10)+'+';
      } else{
        return (parseInt(num/100)*100)+'+';
      }
    }
  }
}
</script>
<style>
  .licc-goods-goods-list-top-row{
    width: 100%;
    margin-top: 20px;
  }
  .liccc-goods-goods-list-bread{
    width: 1100px;
    text-align: left;
    height: 50px;
    line-height: 50px;
    padding-left: 20px;
    background-color: #fff;;
  }
  .liccc-goods-goods-list-bread a {
    color: #333;
  }
  .liccc-goods-goods-list-bread b {
    margin: 0 8px 0 5px;
  }

  .licc-goods-goods-list-center{
    width: 1100px;
  }
  /** 商品列表--开始 **/
  .licc-goods-goods-list-hr-col{
    width: 470px;
    height: 30px;
  }
  .licc-goods-goods-list-hr-div{
    width: 100%;
    height: 0;
    border-top: 1px solid #ededed;
    margin:auto;
    margin-top: 15px;
  }
  .licc-goods-goods-list-col{
    width: 265px;
    margin-left: 4px;
    margin-right: 4px;
    height: 450px;
    margin-top: 10px;
    background-color: #fff;
  }
  .licc-goods-goods-list-col:hover{
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)
  }
  .licc-goods-goods-list-info{
    padding: 12px 7px;
    font: 12px/150% tahoma,arial,Microsoft YaHei,Hiragino Sans;
  }
  .licc-goods-goods-list-img{
    height: 320px;
    margin-bottom: 5px;
  }
  .licc-goods-goods-list-price{
    height: 22px;
    line-height: 22px;
    overflow: hidden;
    width: 100%;
    margin: 0 0 8px;
  }
  .J_price{
    float: left;
    margin-right: 10px;
    color: #e4393c;
    font-size: 20px;
  }
  .licc-goods-goods-list-name{
    height: 40px;
    text-align: left;
    line-height: 20px;
    margin-bottom: 8px;
    overflow: hidden;
  }
  .licc-goods-goods-list-name a{
    color: #666;
    text-decoration: none;
  }
  .licc-goods-goods-list-name a:hover{
    color: #f30213;
  }
  .licc-goods-commit, .licc-goods-integral{
    width: 50%;
    float: left;
    height: 18px;
    margin-bottom: 8px;
    overflow: hidden;
  }
  .licc-goods-commit strong, .licc-goods-integral strong{
    float: left;
    margin-right: 10px;
    color: #a7a7a7;
  }
  .licc-goods-commit a, .licc-goods-integral a{
    color: #646fb0;
    text-decoration: none;
  }
  /** 商品列表--结束 **/
  /* 分页--开始*/
  .licc-goods-list-pagination{
    width: 100%;
    background-color: #ffffff;
  }
  /* 分页--结束*/
</style>
